package com.example.designpattern.behavior.visitor;

import java.util.ArrayList;
import java.util.List;

public class TestVisitor {

	/**
	 * There are many type of Router with different implements. Each router in different environment, there is different configuration.
	 * If in the future, there is new router or new Environment, so it will damage old source code. Visitor Design Pattern will resolve it.
	 * Example in future, if we want implement for Mac OS Environment, we only create class MaxConfigurator implement RouterVisitor, and we do not need to change other class in the hierarchy . 
	 */
	public static void main(String[] args) {
		Router dlinkRouter = new DLinkRouter();
		Router linkSysRouter = new LinkSysRouter();
		Router tpLinkRouter = new TPLinkRouter();
		List<Router> routers = new ArrayList<Router>();
		routers.add(dlinkRouter);
		routers.add(linkSysRouter);
		routers.add(tpLinkRouter);
		
		//config Window
		RouterVisitor windowVisitor = new WindowsConfigurator();
		for(Router router : routers) {
			router.accept(windowVisitor);
			router.sendData(new char[] {'a', 'b'});
			router.acceptData(new char[] {'a', 'b'});
			System.out.println("---");
		}
		
		//config Linux
		RouterVisitor linuxVisitor = new LinuxConfigurator();
		for(Router router : routers) {
			router.accept(linuxVisitor);
			router.sendData(new char[] {'a', 'b'});
			router.acceptData(new char[] {'a', 'b'});
			System.out.println("---");
		}
		
		System.out.println("#########");
		List<RouterVisitor> visitors = new ArrayList<RouterVisitor>();
		visitors.add(windowVisitor);
		visitors.add(linuxVisitor);
		for(RouterVisitor visitor : visitors) {
			for(Router router : routers) {
				router.accept(visitor);
				router.sendData(new char[] {'a', 'b'});
				router.acceptData(new char[] {'a', 'b'});
				System.out.println("---");
			}
		}
		
	}

}
